﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AGameOfThrones.cards
{
    /// <summary>
    /// Interaction logic for card.xaml
    /// </summary>
    public partial class card : UserControl
    {
        private Point oldMousePos;

        public static readonly DependencyProperty ImageProperty =
        DependencyProperty.Register("Image", typeof(ImageSource), typeof(card), new UIPropertyMetadata(null));

        public ImageSource Image
        {
            get { return (ImageSource)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        public card()
        {
            InitializeComponent();
        }

        private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.UIElement uielement = sender as System.Windows.UIElement;
            uielement.CaptureMouse();
            oldMousePos = e.GetPosition(uielement);
        }

        private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.UIElement uielement = sender as System.Windows.UIElement;
            uielement.ReleaseMouseCapture();     
        }

        private void Rectangle_MouseMove(object sender, MouseEventArgs e)
        {
            System.Windows.UIElement uielement = sender as System.Windows.UIElement;
            if (uielement.IsMouseCaptured)
            {
                Point newMousePos = e.GetPosition(uielement);

                double dx = newMousePos.X - oldMousePos.X;
                double dy = newMousePos.Y - oldMousePos.Y;

                TranslateTransform t = uielement.RenderTransform as TranslateTransform;
                t.X += dx;
                t.Y += dy;
            }
        }

        private void card_control_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void card_control_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

        }
    }
}
